package com.sjsayers.tipCalc;

import java.text.NumberFormat;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class tipCalc extends Activity implements
android.view.View.OnClickListener {
	
	//Create the public GUI refers.
	EditText billEditText;
	EditText tipPercentEditText;
	Button calculateButton;
	
    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        //Initialize the GUI
        billEditText = (EditText)this.findViewById(R.id.billEditText);
        tipPercentEditText = (EditText)this.findViewById(R.id.tipPercentEditText);
        calculateButton = (Button)this.findViewById(R.id.calculateButton);
        calculateButton.setOnClickListener(this);
    }
    /**
     * Grabs the bill value from billEditText
     * @return float bill
     */
    public float getBill(){
    	return Float.parseFloat(billEditText.getText().toString());
    }
    /**
     * Grabs the tip percentage from the GUI tipPercentEditText
     * @return float tip
     */
    public float getTipPercent(){
    	return Float.parseFloat(tipPercentEditText.getText().toString());
    }
    /**
     * Calculates how much you should tip.
     * @return float tip
     */
    public float calculateTip(){
    	float tipPercent = getTipPercent() / 100;
    	float bill = getBill();
    	float tip = (bill * tipPercent);
    	return tip;
    }


	@Override
	/**
	 * Done when the GUI button calculate is pressed, shows a Dialog.
	 */
	public void onClick(View arg0) {
		String message = "Bill : "+currencyFormat.format(getBill())+"\n"+"Tip % : "+getTipPercent()+"%\n"+"Tip : "+currencyFormat.format(calculateTip());
		showAlert("End Bill", 0, message, "Thanks!", false);
		
	}
}